//edit页面使用begin ===========================================================
//var params = {};
//var current = {};
//var defaultPageSize = 10;
//var currentPage = 1;
//var pageSize = defaultPageSize;
//var option = {};
// 编辑入口
$(function() {
	var id = localStorage.getItem("rowId");
	localStorage.removeItem("rowId");
	getEntityById(id);
	$('.add').on('click', updateEntity);
	$('.empty').on('click', cancel);
	$('.check').on('click', queryVendorLov);
	$('#materielQuery').on('click', queryMatLov);
	$('#contractLineQuery').on('click', contractLineQuery);
//	$('#buyerQuery').on('click', employeeQuery);
	$("#buyerQuery").bind('click', function() {
		employeeQuery('#employeeNameLov');
	});
	$("#vendorName").click(lovVendor);
	$("#buyerName").bind('click',function(){lovEmployee('buyer')});
});
var seq = 1;
function getEntityById(id) {
	$.ajax({
		url : webUrl + 'scheduling/getEntityById.do',
		type : 'post',
		data : {
			id : id
		}
	}).done(
			function(data) {
				var d = data.bo;
				// 初始化
				$("#poHeaderId").val(d.chwPoHeader.poHeaderId);
				if (d.chwPoHeader.segment1 != null) {
					$("#segment1").val(d.chwPoHeader.segment1);
				}
				if (d.chwPoHeader.vendorId != null) {
					$("#vendorId").val(d.chwPoHeader.vendorId);
				}
				if (d.chwPoHeader.vendorName != null) {
					$("#vendorName").val(d.chwPoHeader.vendorName);
				}
				if (d.chwPoHeader.buyer != null) {
					$("#buyer").val(d.chwPoHeader.buyer);
				}
				if (d.chwPoHeader.buyerName != null) {
					$("#buyerName").val(d.chwPoHeader.buyerName);
				}
				if (d.chwPoHeader.sumAmount != null) {
					$("#sumAmount").val(d.chwPoHeader.sumAmount);
				} else {
					$("#sumAmount").val(0.0);
				}
				$("#SelStatus option").each(function() {
					if ($(this).val() == d.chwPoHeader.status) {
						$(this).attr("selected", true)
						// $(this).attr("selected","selected")两者都可以选中
					}
				});
				$("#SelPriority option").each(function() {
					if ($(this).val() == d.chwPoHeader.priority) {
						$(this).attr("selected", true)
						// $(this).attr("selected","selected")两者都可以选中
					}
				});
				if (d.chwPoHeader.purchaseOrderDate != null) {
					$('#purchaseOrderDate')
							.datebox(
									'setValue',
									formatDate(new Date(
											d.chwPoHeader.purchaseOrderDate)));
				}
				if (d.chwPoHeader.remark != null) {
					$("#remark").val(d.chwPoHeader.remark);
				}
				if (d.lineList !== null && d.lineList !== undefined
						&& d.lineList !== '') {
					for (var i = d.lineList.length - 1; i >= 0; i--) {
						addLine('fillValue',d.lineList[i]);
					}
				}
			});
}
// edit页面使用end =============================================================
